﻿namespace PhotobucketNet
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    internal class QueryParameterList : List<QueryParameter>
    {
        public string NormalizeRequestParameters()
        {
            StringBuilder builder = new StringBuilder();
            QueryParameter parameter = null;
            for (int i = 0; i < base.Count; i++)
            {
                parameter = base[i];
                if (string.IsNullOrEmpty(parameter.Value))
                {
                    builder.AppendFormat("{0}", parameter.Name);
                }
                else
                {
                    builder.AppendFormat("{0}={1}", parameter.Name, parameter.Value);
                }
                if (i < (base.Count - 1))
                {
                    builder.Append("&");
                }
            }
            return builder.ToString();
        }

        public void Sort()
        {
            base.Sort(new QueryParameterComparer());
        }
    }
}

